#!/usir/bin/perl
use strict;
use warnings;
use XML::Simple;
use Data::Dumper;
 
my $cmd_result = "/epot/Sources/SystemDevelopment/CP_Development/Releases/Usman_Test_CP_Development/msp/clip";
my $branch = "Usman_Branch";
my $ws_address = "/home/usman/workspace";
update_git($cmd_result);
sub update_git {
  my $new_p4_path = shift;
  my $workspace = "/home/usman/testws";
  my $xml = XML::Simple->new;
  my $data_structure = $xml->XMLin("/home/usman/branch.xml");
  my $info = $data_structure->{'branch'};
  my $counter = 0;
  foreach my $item (@$info) {
    my $p4_path = $item->{'depot_path'};
    my $local_ws = $item->{'git_ws'};
    #print "$item->{'depot_path'}\n";
   if ($new_p4_path =~ /$p4_path/) {
     $counter = 1;
     ws_exists();
     last
    }
  }
  if (! $counter) {
  add_info($data_structure, $new_p4_path, $ws_address, $branch)
  }
}
  
sub ws_exists {
  print "Depot path mathches\n";
}
 
sub create_ws {
  print "Depot path does not match!!!!\n";
}
sub add_info {
my $file = "/home/usman/branch.xml";
my ($hash_structure, $dpath, $git_ws_path, $branch_name) = @_;
my $xml = XML::Simple->new;
my $array_structure = ($hash_structure->{'branch'});
push @{$hash_structure->{'branch'}}, {
   depot_path  => $dpath,
   git_ws      => $git_ws_path,
   branch_name => $branch_name
};
my $output = $xml->XMLout($hash_structure, Rootname=>'branch_specs', XMLDecl => 1);
open (my $file_handle, '>', $file) or die "Cannot open this file $!";
print $file_handle "$output\n";
close ($file_handle);
return;
   } #add_info
